/**
 * 
 */
package test0.dao.proxy;

import java.util.List;

import test0.dao.idao.IEmpDAO;
import test0.dao.dbc.DatabaseConnection;
import test0.dao.impl.EmpDAOimpl;
import test0.dao.vo.Emp;


public class EmpDAOProxy implements IEmpDAO {
	private DatabaseConnection dbc=null;
	private IEmpDAO dao=null;
	
	public EmpDAOProxy() {
		this.dbc=new DatabaseConnection();
		this.dao=new EmpDAOimpl(this.dbc.getConnection());
	}
	
	public boolean doCreate(Emp emp) throws Exception {
		// TODO Auto-generated method stub
		boolean flag=false;
		try {
			if (this.dao.findByid(emp.getEmpno())==null) {
				flag=this.dao.doCreate(emp);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw e;
		}finally {
			this.dbc.close();
		}
		
		return flag;
	}


	public List<Emp> findAll(String keyWord) throws Exception {
		// TODO Auto-generated method stub
		List<Emp> all=null;
		try {
			all = this.dao.findAll(keyWord);
		} catch (Exception e) {
			// TODO: handle exception
			throw e;
		}finally {
			this.dbc.close();
		}
		return all;
	}

	public Emp findByid(int empno) throws Exception {
		// TODO Auto-generated method stub
		Emp emp=null;
		try {
			emp=this.dao.findByid(empno);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw e;
		}finally {
			this.dbc.close();
		}
		return emp;
	}

}
